﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SCG.WinForms
{
    public static class ImageColorizer
    {
        //get colorized version of an image
        public static Bitmap Colorize(Bitmap img, Color color, Color transparent)
        {
            string key = color.Code();
            if (_mappings.ContainsKey(img))
            {
                Dictionary<string, Bitmap> mapping = _mappings[img];
                if (mapping.ContainsKey(key))
                {
                    return mapping[key];
                }
                else
                {
                    Bitmap colorized = ImageUtils.ColorizeBitmap(img, color, transparent);
                    mapping[key] = colorized;
                    return colorized;
                }
            }
            else
            {
                Dictionary<string, Bitmap> mapping = new Dictionary<string, Bitmap>();
                _mappings[img] = mapping;
                Bitmap colorized = ImageUtils.ColorizeBitmap(img, color, transparent);
                mapping[key] = colorized;
                return colorized;
            }
        }

        //dictionary mapping images to color versions
        private static Dictionary<Bitmap, Dictionary<string, Bitmap>> _mappings = new Dictionary<Bitmap, Dictionary<string, Bitmap>>();
    }
}
